<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单编号">
              <a-input placeholder="请输入" v-model="queryParam.orderSn"></a-input>
            </a-form-item>
          </a-col>
      
       <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="客户名称">
              <a-input placeholder="请输入" v-model="queryParam.companyName"></a-input>
            </a-form-item>
          </a-col>
      
	  <a-col :xl="6" :lg="7" :md="8" :sm="24">
	     <a-form-item label="退款状态">
	     <a-select
	     v-model="queryParam.status"
	       style="width: 150px"
	       @focus="focus"
	       ref="select"
	       @change="handleChange"
	        placeholder="请选择"
	     >
	       <a-select-option value="0">
	         待审核
	       </a-select-option>
	       <a-select-option value="1" >
	          已拒绝
	       </a-select-option>
		   <a-select-option value="2" >
		      已同意
		   </a-select-option>
	     </a-select>
	     </a-form-item>
	   </a-col>
      
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-button type="primary" @click="searchQuery" icon="search" style="color: #F9D532;width: 80px;height: 36px;background: #333333;border-style: none;">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="color: #F9D532;width: 80px;height: 36px;background: #333333;border-style: none;margin-left: 8px">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>





      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">

        <div slot="filterDropdown">
          <a-card>
            <a-checkbox-group @change="onColSettingsChange" v-model="settingColumns" :defaultValue="settingColumns">
              <a-row>
                <template v-for="(item,index) in defColumns">
                  <template v-if="item.key!='rowIndex'&& item.dataIndex!='action'">
                    <a-col :span="12"><a-checkbox :value="item.dataIndex">{{ item.title }}</a-checkbox></a-col>
                  </template>
                </template>
              </a-row>
            </a-checkbox-group>
          </a-card>
        </div>
        <a-icon slot="filterIcon" type='setting' :style="{ fontSize:'16px',color:  '#108ee9' }" />

        <span slot="action" slot-scope="text, record">
          <a @click="seeorder(record)">查看订单</a> &nbsp;
               <a  @click="seeConfirmRefund(record)"  v-if="record.status==0">确认退款</a> &nbsp;
			   
<!--    <a-popconfirm title="确定同意退款吗?" @confirm="() => approve(record)">
                  <a>确认退款</a>
                </a-popconfirm> &nbsp; -->



    <a-popconfirm title="确定拒绝吗?" @confirm="() => refuse(record)">
                  <a v-if="record.status==0">拒绝</a>
                </a-popconfirm>
          <a-divider type="vertical"/>
      
        </span>

      </a-table>
    </div>
    

<ConfirmRefund ref="seeConfirmRefund" @aaa="searchQuery" ></ConfirmRefund>

  </a-card>
</template>
<script>
	 import ConfirmRefund from './modules/ConfirmRefund';
  import JSuperQuery from '@/components/jeecg/JSuperQuery.vue';
  import JInput from '@/components/jeecg/JInput.vue';
  import {initDictOptions, filterDictText,filterDictTextByCache} from '@/components/dict/JDictSelectUtil'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import Vue from 'vue'
  import { filterObj } from '@/utils/util';
import { getAction } from '../../api/manage';

  //高级查询modal需要参数
  const superQueryFieldList=[
    {
      type: "string",
      value: "name",
      text: "用户名"
    }, {
      type: "int",
      value: "age",
      text: "年龄"
    }, {
      type: "date",
      value: "birthday",
      text: "生日"
    }
  ]
  export default {
    name: "RefundList",
    mixins:[JeecgListMixin],
    components: {
      JSuperQuery,
      JInput,
			ConfirmRefund
    },
    data() {
      return {
        description: '单表示例列表',
        //字典数组缓存
        sexDictOptions: [],
        importExcelUrl:`${window._CONFIG['domianURL']}/test/jeecgDemo/importExcel`,
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        //列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key: 'rowIndex',
            width: 60,
            align: "center",
            customRender: function (t, r, index) {
              return parseInt(index) + 1;
            }
          },
          {
            title: '订单编号',
            align: "center",
            dataIndex: 'orderSn'
          },
          {
            title: '创建时间',
            align: "center",
            dataIndex: 'createTime'
          },
          {
            title: '客户名称',
            align: "center",
            dataIndex: 'companyName'
          },
                 {
            title: '订单类型',
            align: "center",
            dataIndex: 'orderType',
            customRender: (orderType) => {
              //字典值替换通用方法
              if(orderType==0)
              return "面料下单";
              else if(orderType==1)
              return "个订下单";
              else  if(orderType==2)
              return "团订下单";
              else
               return "成衣下单";
            }
          },
           {
            title: '订单金额',
            align: "center",
            dataIndex: 'orderMoney'
          },
           {
            title: '状态',
            align: "center",
            dataIndex: 'status',
            customRender: (status) => {
              //字典值替换通用方法
              if(status==0)
              return "审核中";
              else if(status==1)
              return "已拒绝";
              else 
              return "已退款";
            }
          },
          {
            title: '退款金额',
            align: "center",
            dataIndex: 'returnMoney'
          },
          // {
          //   title: '状态',
          //   align: "center",
          //   dataIndex: 'status',
          //   customRender: (status) => {
          //     //字典值替换通用方法
          //     if(status==1)
          //     return "停用";
          //     else
          //     return "启用中";
          //   }
          // },
          {
            title: '操作',
            dataIndex: 'action',
            align: "center",
            scopedSlots: {
              filterDropdown: 'filterDropdown',
              filterIcon: 'filterIcon',
              customRender: 'action'},
          }
        ],
        url: {
          list: "/returnMoney/list",
          delete: "/returnMoney/refuse",
           approve:"/returnMoney/approve"
        },
        fieldList:superQueryFieldList
      }
    },
    methods: {
  //确认退款的弹出框
 seeConfirmRefund: function (record) {
      this.$refs.seeConfirmRefund.edit(record);
      this.$refs.seeConfirmRefund.title = "确认退款";
      this.$refs.seeConfirmRefund.disableSubmit = false;
    },



   //查看订单详情
   seeorder(record){
      console.log("看一看传过来的类型"+record.orderType)

      if(record.orderType==0){
        //跳转到面料详情
           this.$router.push({path:'/orderCenter/fabricDetail',query: {order:record.orderSn}})
      }else if(record.orderType==1){
        //跳转到个订详情
           this.$router.push({path:'/orderCenter/singleDetail',query: {order:record.orderSn}})
      }else if(record.orderType==2){
        //跳转到团订详情
            this.$router.push({path:'/orderCenter/teamDetail',query: {order:record.orderSn}})
      }else{
         //跳到成衣详情
      }


   },

       //拒绝
     refuse(record){
            
            getAction(this.url.delete,{"id":record.id,"userId":record.userId,"money":record.orderMoney,"orderSn":record.orderSn}).then((res)=>{
              if(res.success){
                this.$message.success(res.message);
             this.searchQuery();
              }else{
                this.$message.warning(res.message);
              } })
     },

     //同意退款
     approve(record){
               getAction(this.url.approve,{"id":record.id,"userId":record.userId,"money":record.returnMoney}).then((res)=>{
              if(res.success){
                this.$message.success(res.message);
                this.searchQuery();
              }else{
                this.$message.warning(res.message);
              } })
     },
      getQueryParams(){
        //高级查询器
        let sqp = {}
        if(this.superQueryParams){
          sqp['superQueryParams']=encodeURI(this.superQueryParams)
          sqp['superQueryMatchType'] = this.superQueryMatchType
        }
        var param = Object.assign(sqp, this.queryParam, this.isorter ,this.filters);

        param.field = this.getQueryField();
        param.pageNo = this.ipagination.current;
        param.pageSize = this.ipagination.pageSize;
        delete param.birthdayRange; //范围参数不传递后台
        return filterObj(param);
      },
 
      onetomany: function () {
        this.$refs.jeecgDemoTabsModal.add();
        this.$refs.jeecgDemoTabsModal.title = "编辑";
      },
  
 
      //列设置更改事件
      onColSettingsChange (checkedValues) {
        var key = this.$route.name+":colsettings";
        Vue.ls.set(key, checkedValues, 7 * 24 * 60 * 60 * 1000)
        this.settingColumns = checkedValues;
        const cols = this.defColumns.filter(item => {
          if(item.key =='rowIndex'|| item.dataIndex=='action'){
            return true
          }
          if (this.settingColumns.includes(item.dataIndex)) {
            return true
          }
          return false
        })
        this.columns =  cols;
      },
      initColumns(){
        //权限过滤（列权限控制时打开，修改第二个参数为授权码前缀）
        //this.defColumns = colAuthFilter(this.defColumns,'testdemo:');

        var key = this.$route.name+":colsettings";
        let colSettings= Vue.ls.get(key);
        if(colSettings==null||colSettings==undefined){
          let allSettingColumns = [];
          this.defColumns.forEach(function (item,i,array ) {
            allSettingColumns.push(item.dataIndex);
          })
          this.settingColumns = allSettingColumns;
          this.columns = this.defColumns;
        }else{
          this.settingColumns = colSettings;
          const cols = this.defColumns.filter(item => {
            if(item.key =='rowIndex'|| item.dataIndex=='action'){
              return true;
            }
            if (colSettings.includes(item.dataIndex)) {
              return true;
            }
            return false;
          })
          this.columns =  cols;
        }
      }
    },
    created() {
      this.initColumns();
    },
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>